package com.itheima.polymorphic;

//Human类
class Human {
    private String name;
    private int age;
    private String sex;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public void speak(){
        System.out.println("I am a human.");
    }
    public void run(){
        System.out.println("I can run.");
    }
    public void getInfo(){
        System.out.println("我的名字是："+getName()+" 我的年龄是："+getAge()+" 我的性别是："+getSex());
    }
}

//Man类
class Man extends Human{
    public void man(){
        if(getSex()=="男人"){
            System.out.println("I am a man.");
        }
        else{
            System.out.println("I am not a man.");
        }
    }
    public void run(){
        System.out.println("我是雄狮一样强壮的男人.");
    }
}


//Woman类
class Woman extends Human {
    public void woman(){
        if(getSex()=="女"){
            System.out.println("I am a woman.");
        }
        else{
            System.out.println("I am not a woman.");
        }
    }
}

//测试类
public class TestHuman {
    public static void main(String[] agrs){
        Man m=new Man();
        m.setName("Dave");
        m.setAge(28);
        m.setSex("男");
        m.getInfo();
        m.speak();
        m.run();
        m.man();
        //隐式转换
        //上转型对象
        Human h=new Woman();
        h.setName("Jude");
        h.setAge(58);
        h.setSex("女");
        h.speak();
        h.run();
        h.getInfo();
        /*if(h instanceof Woman){
            Woman w=(Woman)h;
            w.woman();
        }
        else{
            System.out.println("类型不符！");
        }*/
        Woman w = (Woman)h;
        w.woman();
    }
}
